#include <criterion/criterion.h>
#include <criterion/assert.h>
#include "status_link.h"
#include "CxlUtil.h"
#include <execinfo.h>

Test(stausLink, test)
{
    unsigned char initArr[6] = {1, 1, 1, 1, 1, 1};
    log_init("log_all", "./conf/zlog.conf");
    initStatusLink();
    StatusLink *tail = getTailStatus();
    cr_assert_arr_eq(tail->bits, initArr, 6);

    StatusLink *prevStatusLink = getPreviousStatusLink(tail);
    cr_assert_null(prevStatusLink);

    pushStatus(initArr);
    tail = getTailStatus();
    cr_assert_arr_eq(tail->bits, initArr, 6);

    prevStatusLink = getPreviousStatusLink(tail);
    cr_assert_arr_eq(prevStatusLink->bits, initArr, 6);
    StatusLink *prevTwoStatusLink = getPreviousStatusLink(prevStatusLink);
    cr_assert_null(prevTwoStatusLink);

    freeLink();

    unsigned char arr2[6] = {0, 0, 0, 1, 1, 1};
    pushStatus(arr2);
    tail = getTailStatus();
    cr_assert_arr_eq(tail->bits, arr2, 6);
    prevStatusLink = getPreviousStatusLink(tail);
    cr_assert_arr_eq(prevStatusLink->bits, initArr, 6);

    freeLink();

    tail = getTailStatus();
    cr_assert_arr_eq(tail->bits, arr2, 6);
    prevStatusLink = getPreviousStatusLink(tail);
    cr_assert_null(prevStatusLink);
}
